package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityCollect;
import com.ruoyi.cust.service.ICityCollectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏Controller
 *
 * @author cjq
 * @date 2024-12-06
 */
@Api("收藏")
@RestController
@RequestMapping("/city/collect")
public class CityCollectController extends BaseController {
    @Autowired
    private ICityCollectService cityCollectService;

    /**
     * 查询收藏列表
     */
    @ApiOperation("查询收藏列表")
    @PreAuthorize("@ss.hasPermi('city:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityCollect cityCollect) {
        startPage();
        List<CityCollect> list = cityCollectService.selectCityCollectList(cityCollect); return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @ApiOperation("导出收藏列表")
    @PreAuthorize("@ss.hasPermi('city:collect:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityCollect cityCollect) {
        List<CityCollect> list = cityCollectService.selectCityCollectList(cityCollect); ExcelUtil<CityCollect> util = new ExcelUtil<CityCollect>(CityCollect. class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @ApiOperation("获取收藏详细信息")
    @PreAuthorize("@ss.hasPermi('city:collect:query')")
    @GetMapping(value = "/{collectId}")
    public AjaxResult getInfo(@PathVariable("collectId") Long collectId) {
        return success(cityCollectService.selectCityCollectByCollectId(collectId));
    }

    /**
     * 新增收藏
     */
    @ApiOperation("新增收藏")
    @PreAuthorize("@ss.hasPermi('city:collect:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityCollect cityCollect) {
        return toAjax(cityCollectService.insertCityCollect(cityCollect));
    }

    /**
     * 修改收藏
     */
    @ApiOperation("修改收藏")
    @PreAuthorize("@ss.hasPermi('city:collect:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityCollect cityCollect) {
        return toAjax(cityCollectService.updateCityCollect(cityCollect));
    }

    /**
     * 删除收藏
     */
    @ApiOperation("删除收藏")
    @PreAuthorize("@ss.hasPermi('city:collect:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{collectIds}")
    public AjaxResult remove(@PathVariable Long[] collectIds) {
        return toAjax(cityCollectService.deleteCityCollectByCollectIds(collectIds));
    }
}
